﻿using System;
using System.Linq;
using System.Linq.Dynamic;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using ChoViet.CMS.Properties;
using ChoViet.CMS.ViewModels;
using ChoViet.Lib.Common;
using ChoViet.Lib.Helpers;
using ChoViet.Lib.Paging;
using ChoViet.Model;
using ChoViet.CMS.Components;
using System.Web.UI;

namespace ChoViet.CMS.Controllers
{
    public class CounterController : BaseController
    {
        //
        // GET: /Counter/

        public ChoVietDataContext eDataContext = new ChoVietDataContext();
        [ChildActionOnly]
        //[OutputCache(Duration=600,VaryByParam="none")]
        public ActionResult Visited()
        {
            CounterViewModels c = new CounterViewModels();
            c.TotalVisited = eDataContext.Counters.Sum(e => e.Visited).Value;
            var y = eDataContext.Counters.Where(a => a.AddDate.Value.Day == DateTime.Now.AddDays(-1).Day && a.AddDate.Value.Month == DateTime.Now.Month).FirstOrDefault();
            var beforeY = eDataContext.Counters.Where(e => e.AddDate.Value.Day == DateTime.Now.AddDays(-2).Day && e.AddDate.Value.Month == DateTime.Now.Month ).FirstOrDefault();
            c.BeforeYesterday = beforeY != null ? beforeY.Visited : 0;
            c.Yesterday = y != null ? y.Visited : 0;
            return View(c);
        }
    }
}
